package com.javafactroy.kunlong.domain.generalquery.repository;

import com.javafactroy.kunlong.base.exception.BusinessException;
import com.javafactroy.kunlong.base.model.ReturnPageInfo;
import com.javafactroy.kunlong.common.utils.CommonUtils;
import com.javafactroy.kunlong.data.dto.QueryConditionApiDto;
import com.javafactroy.kunlong.data.entity.QueryConditionApiEntity;
import com.javafactroy.kunlong.data.entity.QueryMasterApiEntity;
import com.javafactroy.kunlong.domain.generalquery.agg.QueryMasterMultiAgg;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Slf4j
public class QueryMasterMultiAggRepository extends QueryMasterAggRepository{
    public QueryMasterMultiAgg load(Long masterId) {
        QueryMasterApiEntity entity = queryMasterService.selectByPkey(masterId);
        if (entity == null) {
            throw new BusinessException(500, "配置的查询不存在！");
        }
        log.info("master=\r\n{}", CommonUtils.toJSONString(entity));
        ReturnPageInfo<QueryConditionApiEntity> pi = queryConditionService.query(new QueryConditionApiDto().setMasterId(masterId));
        List<QueryConditionApiDto> dtos = queryConditionApiConvert.toList(pi.getList());
        return new QueryMasterMultiAgg().setMasterId(masterId);

    }

}
